﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RyanLam.NET.Templates.AdminControl.Menu
{
    [
    DefaultProperty("Text"),
    ParseChildren(true),
    PersistChildren(false),
    ToolboxData("<{0}:ACPage runat=\"server\"></{0}:ACPage>")
    ]
    public class ACPage : CompositeControl
    {
        #region Private Member Variables
        private string siteName;
        private string siteVersion;
        private Panel header;
        private ACPageIPathway pathWay;
        private ACPageIContent content;
        private Panel footer;
        //menu control
        private int menuParentID;
        private Core.ITemplates.EnumTrueOrFalse menuReloadData;
        private Core.ITemplates.EnumTrueOrFalse menuCheckLoginPermission;
        private int menuCurrentMainMenuID = 1;
        private int menuCurrentSubMenuID = 1;
    
        #endregion


        #region Properties

        #region SiteName
        /// <summary>
        /// Site's name.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(""),
        Description("Site's name."),
        Localizable(true)
        ]
        public string SiteName
        {
            get
            {
                return this.siteName;
            }
            set
            {
                this.siteName = value;
            }
        }
        #endregion

        #region SiteVersion
        /// <summary>
        /// Site's version.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(""),
        Description("Site's version."),
        Localizable(true)
        ]
        public string SiteVersion
        {
            get
            {
                return this.siteVersion;
            }
            set
            {
                this.siteVersion = value;
            }
        }
        #endregion
        
        #region Header
        /// <summary>
        /// Display header block.
        /// </summary>
        [NotifyParentProperty(true)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public Panel Header
        {
            get { return this.header; }
            set { this.header = value; }
        }

        #endregion

        #region PathWay
        /// <summary>
        /// Site pathway.
        /// </summary>
        [NotifyParentProperty(true)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public ACPageIPathway PathWay
        {
            get { return this.pathWay; }
            set { this.pathWay = value; }
        }

        #endregion

        #region Content
        /// <summary>
        /// Content.
        /// </summary>
        [NotifyParentProperty(true)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public ACPageIContent Content
        {
            get { return this.content; }
            set { this.content = value; }
        }
        #endregion

        #region Footer
        /// <summary>
        /// Block's footer details.
        /// </summary>
        [
        NotifyParentProperty(true),
        PersistenceMode(PersistenceMode.InnerProperty),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        Description("Block's footer details."),
        ]
        public Panel Footer
        {
            get { return this.footer; }
            set { this.footer = value; }
        }
        #endregion


        #region MenuParentID
        /// <summary>
        /// Menu parent id.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(0),
        Description("Menu parent id."),
        Localizable(true)
        ]
        public int MenuParentID
        {
            get
            {
                return this.menuParentID;
            }
            set
            {
                this.menuParentID = value;
            }
        }
        #endregion

        #region MenuReloadData
        /// <summary>
        /// Refresh menu's data on memory.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(Core.ITemplates.EnumTrueOrFalse.True),
        Description("Refresh menu's data on memory."),
        Localizable(true)
        ]
        public Core.ITemplates.EnumTrueOrFalse MenuReloadData
        {
            get
            {
                return this.menuReloadData;
            }
            set
            {
                this.menuReloadData = value;
            }
        }
        #endregion

        #region MenuCheckLoginPermission
        /// <summary>
        /// Checking current user login's permission (this process will be based on ASP.NET Membership Built-in).
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(Core.ITemplates.EnumTrueOrFalse.False),
        Description("Checking current user login's permission (this process will be based on ASP.NET Membership Built-in)."),
        Localizable(true)
        ]
        public Core.ITemplates.EnumTrueOrFalse MenuCheckLoginPermission
        {
            get
            {
                return this.menuCheckLoginPermission;
            }
            set
            {
                this.menuCheckLoginPermission = value;
            }
        }
        #endregion

        #region MenuCurrentMainMenuID
        /// <summary>
        /// Selected current main menu id.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(0),
        Description("Selected current main menu id."),
        Localizable(true)
        ]
        public int MenuCurrentMainMenuID
        {
            get
            {
                return this.menuCurrentMainMenuID;
            }
            set
            {
                this.menuCurrentMainMenuID = value;
            }
        }
        #endregion

        #region MenuCurrentSubMenuID
        /// <summary>
        /// Selected current sub menu id.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(0),
        Description("Selected current sub menu id."),
        Localizable(true)
        ]
        public int MenuCurrentSubMenuID
        {
            get
            {
                return this.menuCurrentSubMenuID;
            }
            set
            {
                this.menuCurrentSubMenuID = value;
            }
        }
        #endregion

        #endregion

        #region Overrides
        protected override void CreateChildControls()
        {
            Controls.Clear();
            if (this.header == null) this.header = new Panel(); this.Controls.Add(this.header);
            if (this.content == null) this.content = new ACPageIContent() ; this.Controls.Add(this.content);
            if (this.footer == null) this.footer = new Panel(); this.Controls.Add(this.footer);
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.Write(@"<!--[if lt IE 9]><div class='ie'><![endif]-->");
            writer.Write(@"<!--[if lt IE 8]><div class='ie7'><![endif]-->");
            writer.Write(@"<header>");
            writer.Write(@"<div class='container_12'>");
            writer.Write(String.Format(@"<p id='skin-name'><small>{0}</small> <strong>{1}</strong></p>",
                this.siteName != null ? this.SiteName : String.Empty,
                this.siteVersion != null ? this.SiteVersion : String.Empty
               ));
            writer.Write(@"<div class='server-info'>Server: <strong>Apache 2.2.X (OVH)</strong></div>");
            writer.Write(@"<div class='server-info'>Php: <strong>5.2.17</strong></div>");
            writer.Write(@"</div>");
            writer.Write(@"</header>");

            ACMenu menu = new ACMenu
            {
                ParentID = this.MenuParentID,
                ReloadData = this.MenuReloadData, 
                CheckLoginPermission = this.MenuCheckLoginPermission,
                CurrentMainMenuID = this.MenuCurrentMainMenuID,
                CurrentSubMenuID = this.MenuCurrentSubMenuID
            };
            menu.RenderControl(writer);

            writer.Write(@"<div id='sub-nav'>");
            writer.Write(@"<div class='container_12'>");
            writer.Write(@"<a href='javascript:void(0)' title='Help' class='nav-button'><b>Help</b></a>");
            writer.Write(@"<div id='search-form' name='search-form' method='post' action='search.php'>");
            writer.Write(@"<input type='text' name='s' id='s' value='' title='Search admin...' autocomplete='off'>");
            writer.Write(@"</div>");
            writer.Write(@"</div>");
            writer.Write(@"</div>");

            writer.Write(@"<div id='status-bar'>");
            writer.Write(@"<div class='container_12'>");
            writer.Write(@"<ul id='breadcrumb'>");
            writer.Write(@"<li><a href='javascript:void(0)' title='Home'>Home</a></li>");
            writer.Write(@"<li><a href='javascript:void(0)' title='Dashboard'>Dashboard</a></li>");
            writer.Write(@"</ul>");
            writer.Write(@"<ul id='status-infos'>");
            writer.Write(@"<li class='spaced'>Logged as: <strong>Admin</strong></li>");
            writer.Write(@"<li><a href='javascript:void(0)' class='button' title='5 messages'>");
            writer.Write(@"<img src='images/icons/fugue/mail.png' width='16' height='16'>");
            writer.Write(@"<strong>5</strong></a>");
            writer.Write(@"<div id='messages-list' class='result-block'>");
            writer.Write(@"<span class='arrow'><span></span></span>");
            writer.Write(@"<ul class='small-files-list icon-mail'>");
            writer.Write(@"<li><a href='javascript:void(0)'><strong>2 days</strong> Database backup<br>");
            writer.Write(@"<small>From: System</small></a> </li>");
            writer.Write(@"<li><a href='javascript:void(0)'><strong>2 days</strong> Re: bug report<br>");
            writer.Write(@"<small>From: Max</small></a> </li>");
            writer.Write(@"</ul>");
            writer.Write(@"<p id='messages-info' class='result-info'>");
            writer.Write(@"<a href='javascript:void(0)'>Go to inbox &raquo;</a></p>");
            writer.Write(@"</div>");
            writer.Write(@"</li>");
            writer.Write(@"<li><a href='login.php' class='button red' title='Logout'><span class='smaller'>LOGOUT</span></a></li>");
            writer.Write(@"</ul>");
            writer.Write(@"</div>v</div>");


            this.Content.RenderControl(writer);
            writer.Write(@"<footer>");
            writer.Write(@"<div class='float-right'>");
            writer.Write(@"<a href='#top' class='button'><img src='images/icons/fugue/navigation-090.png' width='16' height='16'> Page top</a>");
            writer.Write(@"</div>");
            writer.Write(@"</footer>");
            writer.Write(@"<!--[if lt IE 8]></div><![endif]-->");
            writer.Write(@"<!--[if lt IE 9]></div><![endif]-->");
        }
        #endregion
    }
}
